package com.tledu.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author cyrus
 */
public class Broker implements InvocationHandler {

    private ISinger cai;

    public Broker(ISinger cai) {
        this.cai = cai;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("前置通知...");
        // 方法的调用
        Object result;
        try{
            result = method.invoke(cai, args);
            System.out.println("返回结果...");
        }catch (Throwable e){
            System.out.println("异常通知...");
            throw e;
        }finally {
            // 后置通知
            System.out.println("后置通知");
        }
        return result;
    }
}
